Fix 'belt + braces' check in xc_linux_save and improve error handling
authorsmh22@firebug.cl.cam.ac.uk <smh22@firebug.cl.cam.ac.uk>
Mon, 21 Nov 2005 15:40:16 +0000 (16:40 +0100)
committersmh22@firebug.cl.cam.ac.uk <smh22@firebug.cl.cam.ac.uk>
Mon, 21 Nov 2005 15:40:16 +0000 (16:40 +0100)
for live migrate (this includes making shadow enable idempotent).

Signed-off-by: Steven Hand <steven@xensource.com>
tools/libxc/xc_linux_save.c
tools/libxc/xg_save_restore.h
xen/arch/x86/shadow32.c

index 54cdb2ce150e8c389aa577aa56e77e4e88b2a353..0863ac6675aecbc2b859602a36deb19634e715a6 100644 (file)
@@ -798,6 +798,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
     pfn_batch = calloc(MAX_BATCH_SIZE, sizeof(unsigned long));
 
     if ((pfn_type == NULL) || (pfn_batch == NULL)) {
+        ERR("failed to alloc memory for pfn_type and/or pfn_batch arays."); 
         errno = ENOMEM;
         goto out;
     }
@@ -817,7 +818,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
         for (i = 0; i < max_pfn; i++) {
 
             mfn = live_p2m[i];
-            if((live_m2p[mfn] != i) && (mfn != 0xffffffffUL)) { 
+            if((mfn != 0xffffffffUL) && (live_m2p[mfn] != i)) { 
                 DPRINTF("i=0x%x mfn=%lx live_m2p=%lx\n", i, 
                         mfn, live_m2p[mfn]);
                 err++;
@@ -912,7 +913,7 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
                        unless its sent sooner anyhow */
 
                     set_bit(n, to_fix);
-                    if(iter > 1)
+                    if( (iter > 1) && IS_REAL_PFN(n) )
                         DPRINTF("netbuf race: iter %d, pfn %x. mfn %lx\n",
                                 iter, n, pfn_type[batch]);
                     continue;
@@ -1157,6 +1158,13 @@ int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
 
  out:
 
+    if (live) {
+        if(xc_shadow_control(xc_handle, dom, DOM0_SHADOW_CONTROL_OP_OFF, 
+                             NULL, 0, NULL ) < 0) { 
+            DPRINTF("Warning - couldn't disable shadow mode");
+        }
+    }
+    
     if (live_shinfo)
         munmap(live_shinfo, PAGE_SIZE);
     
index d4eba303c329af6f4e18b4e57cb47af257dc4536..c735deab41113cd1fa9dd677ddade66250ed44bc 100644 (file)
@@ -125,6 +125,12 @@ static int get_platform_info(int xc_handle, uint32_t dom,
 /* Number of entries in the pfn_to_mfn_frame_list_list */
 #define P2M_FLL_ENTRIES (((max_pfn)+(ulpp*ulpp)-1)/(ulpp*ulpp))
 
+/* Current guests allow 8MB 'slack' in their P2M */
+#define NR_SLACK_ENTRIES   ((8 * 1024 * 1024) / PAGE_SIZE)
+
+/* Is the given PFN within the 'slack' region at the top of the P2M? */
+#define IS_REAL_PFN(_pfn)  ((max_pfn - (_pfn)) > NR_SLACK_ENTRIES) 
+
 /* Returns TRUE if the PFN is currently mapped */
 #define is_mapped(pfn_type) (!((pfn_type) & 0x80000000UL))
 
index e3a53898439e2607432726d46832be748cdcfb6e..91c0e2dc5c2e9ae4006675bdcbb32d1e6ac90515 100644 (file)
@@ -920,9 +920,9 @@ int __shadow_mode_enable(struct domain *d, unsigned int mode)
     struct vcpu *v;
     int new_modes = (mode & ~d->arch.shadow_mode);
 
-    // Gotta be adding something to call this function.
-    ASSERT(new_modes);
-
+    if(!new_modes) /* Nothing to do - return success */
+        return 0; 
+        
     // can't take anything away by calling this function.
     ASSERT(!(d->arch.shadow_mode & ~mode));